Imports Clo = Enhancements.Core.Logging
Imports Ref = System.Reflection
Imports Sys = System

Namespace Enhancements.Basic
    ''' <summary>The exception that is thrown when a value is of a certain type.</summary>
    <Serializable(), DebuggerStepThrough()> _
    Public NotInheritable Class IsOfTypeException
        Inherits AssertException

        Private Sub New(ByVal _objectName As System.String, ByVal _object As Sys.Object, ByVal _objectType As Sys.Type)
            MyBase.New(_objectName)
            [Object] = _object
            ObjectType = _objectType
        End Sub

        Private Sub New(ByVal _objectName As System.String, ByVal _object As Sys.Object, ByVal _objectTypeArray() As Sys.Type)
            MyBase.New(_objectName)
            [Object] = _object
            ObjectTypeArray = _objectTypeArray
        End Sub

        Private __Object As System.Object = Nothing
        ''' <summary>Gets the value of the object that caused this exception.</summary>
        Public Property [Object]() As System.Object
            Get
                Return __Object
            End Get
            Private Set(ByVal _value As System.Object)
                __Object = _value
            End Set
        End Property

        Private __ObjectType As Sys.Type = Nothing
        ''' <summary>Gets the type searched. Only one of the ObjectType and ObjectTypeArray properties is used. If the value here is Null then the ObjectTypeArray property might be in use.</summary>
        Public Property ObjectType() As Sys.Type
            Get
                Return __ObjectType
            End Get
            Private Set(ByVal _value As Sys.Type)
                __ObjectType = _value
            End Set
        End Property

        Private __ObjectTypeArray() As Sys.Type = CType(Sys.Array.CreateInstance(GetType(Sys.Type), 0), Sys.Type())
        ''' <summary>Gets the type array searched. Only one of the ObjectType and ObjectTypeArray properties is used. If the value here is a 0-length array then the ObjectType property might be in use.</summary>
        Public Property ObjectTypeArray() As Sys.Type()
            Get
                Return __ObjectTypeArray
            End Get
            Private Set(ByVal _value() As Sys.Type)
                __ObjectTypeArray = _value
            End Set
        End Property

        ''' <summary>Throws an exception.</summary>
        ''' <param name="_objectName">Name of the object that is causing the exception.</param>
        ''' <param name="_object">Object that is causing the exception.</param>
        ''' <param name="_objectType">Type searched that is causing the exception.</param>
        ''' <exception cref="IsOfTypeException"> </exception>
        Friend Shared Sub ___Throw(ByVal _objectName As System.String, ByVal _object As Sys.Object, ByVal _objectType As Sys.Type)
            Dim _exception As IsOfTypeException = New IsOfTypeException(_objectName, _object, _objectType)

            Throw _exception
        End Sub

        ''' <summary>Throws an exception.</summary>
        ''' <param name="_objectName">Name of the object that is causing the exception.</param>
        ''' <param name="_object">Object that is causing the exception.</param>
        ''' <param name="_objectTypeArray">Type array searched that is causing the exception.</param>
        ''' <exception cref="IsOfTypeException"> </exception>
        Friend Shared Sub ___Throw(ByVal _objectName As System.String, ByVal _object As Sys.Object, ByVal _objectTypeArray() As Sys.Type)
            Dim _exception As IsOfTypeException = New IsOfTypeException(_objectName, _object, _objectTypeArray)

            Throw _exception
        End Sub

    End Class
End Namespace
